package com.example.cofeed.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.cofeed.adapter.CollectAdapter;
import com.example.cofeed.api.ApiService;
import com.example.cofeed.base.BaseListActivity;
import com.example.cofeed.callback.DialogCallback;
import com.example.cofeed.callback.LzyResponse;
import com.example.cofeed.constant.IntentKeyConstant;
import com.example.cofeed.entity.Article;
import com.example.cofeed.entity.History;
import com.lzy.okgo.model.Response;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

public class ArticeCollectActivity extends BaseListActivity<History> {
    private CollectAdapter mCollectAdapter;

    @Override
    protected void bindRecyclerView(RecyclerView recLv) {
        setMainTitle("文章收藏列表");
        recLv.setLayoutManager(new LinearLayoutManager(this));

        mCollectAdapter = new CollectAdapter();
        recLv.setAdapter(mCollectAdapter);
        refreshLayout.setEnableLoadMore(false);
        mCollectAdapter.setOnItemClickListener((adapter, view, position) -> {
            History article = (History) adapter.getData().get(position);
            Intent intent = new Intent(mContext, WebViewActivity.class);
            intent.putExtra(IntentKeyConstant.ID, article.aid);
            intent.putExtra(IntentKeyConstant.URL, article.url);
            startActivity(intent);
        });

    }

    @Override
    protected void loadData(int page, int pageCount) {
        ApiService.favoriteListFavor(this, new DialogCallback<LzyResponse<List<History>>>() {
            @Override
            public void onSuccess(Response<LzyResponse<List<History>>> response) {
                onGetDataSuc(response.body().data);
            }
        });


    }

    @Override
    protected List<History> getData() {
        return mCollectAdapter.getData();
    }

    @Override
    protected void bindData(boolean isRefresh, List<History> list) {
        if (isRefresh){
            mCollectAdapter.setNewData(list);
        }else {
            mCollectAdapter.addData(list);
        }

    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
